//post路由文件

//引入 express
const express = require('express');
//引入postController
const {
    index,
    create,
    update,
    remove
} = require('../controllers/postControllers');

//生成 express.Router 的实例
const router = express.Router();


/**
 * @api {get} /posts 获取帖子列表
 * @apiName index
 * @apiGroup post
 *
 * @apiSuccess {Number} code 错误状态码.
 * @apiSuccess {String} msg 错误信息.
 * @apiSuccess {Array} data 帖子数组.
 */
//GET /posts
router.get('/', index);

/**
 * @api {post} http://localhost:3000/posts 创建帖子列表
 * @apiName create
 * @apiGroup post
 * 
 * @apiParam {String} title 帖子标题
 * @apiParam {String} content 帖子内容
 *
 * @apiSuccess {Number} code 错误状态码.
 * @apiSuccess {String} msg 错误信息.
 */
//POST /posts
router.post('/', create);

/**
 * @api {put} http://localhost:3000/posts:id 编辑帖子
 * @apiName update
 * @apiGroup post
 * 
 * @apiParam {String} title 帖子标题
 * @apiParam {String} content 帖子内容
 *
 * @apiSuccess {Number} code 错误状态码.
 * @apiSuccess {String} msg 错误信息.
 */
//PUT /POSTS/:id
router.put('/:id', update);

/**
 * @api {DELETE} http://localhost:3000/posts:id 删除帖子
 * @apiName remove
 * @apiGroup post
 * 
 * @apiSuccess {Number} code 错误状态码.
 * @apiSuccess {String} msg 错误信息.
 */
// DELETE /posts:id
router.delete('/:id', remove);

//暴露 router 的实例
module.exports = router;